package com.relaxed.enums;

import lombok.Data;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Yakir
 * @Topic SqlTypeEnum
 * @Description
 * @date 2021/12/8 17:24
 * @Version 1.0
 */
@RequiredArgsConstructor
@Getter
public enum SqlTypeEnum {
    STRING("String","varchar(100)",String.class),
    INTEGER("Integer","int(100)",Integer.class),
    BIG_INTEGER("BigInteger","bigint(20)",BigInteger.class),
    Long("Long","integer unsigned", Long.class),
    BYTE("Byte","tinyint(1)",Byte.class),
    BOOLEAN("Boolean","tinyint(1)",Boolean.class),
    FLOAT("Float","float(10,2)",Float.class),
    DOUBLE("Double","double(10,2)",Double.class),
    DATE("Date","datetime",Date.class),
    TIMESTAMP("Timestamp","datetime",Date.class),
    LOCAL_DATE_TIME("LocalDateTime","datetime",LocalDateTime.class),
    BIG_DECIMAL("BigDecimal","decimal(10,2)",BigDecimal.class),
    ;
    /**
     * java type
     */
    private final String clazzText;
    /**
     * sql type
     */
    private final String sqlType;
    private final Class<?> clazz;
    private static Map<String,SqlTypeEnum> MAP=new HashMap<>();
    static {
        MAP.putAll(Arrays.stream(values()).collect(Collectors.toMap(SqlTypeEnum::getClazzText,e->e)));
    }
    /**
     * obtain sql type
     * @author yakir
     * @date 2021/12/8 17:36
     * @param clazzText
     * @return SqlTypeEnum
     */
    public static SqlTypeEnum  getSqlType(String clazzText){
        return  MAP.get(clazzText);
    }
}
